﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MakeTableTool.Serialization
{
    public class FileSaver
    {
        public enum SaveType
        {
            Byte,
        }
        public static bool SaveFile(ExcelTable excel,string savePath, SaveType saveType = SaveType.Byte)
        {
            
            if(saveType == SaveType.Byte)
            {
                TableSerializer tableSerializer = new TableSerializer(excel);
                var bytes =  tableSerializer.ConvertToByte();
                try
                {
                    File.WriteAllBytes(savePath, bytes);
                    return true;
                }
                catch(Exception e)
                {
                    throw new Exception(string.Format("保存数据 {0} 文件出错 :Message {1}",Path.GetFileName(savePath),e.Message));
                }
            }

            return false;
        }


        
    }
}
